<template>
  <div class="app-container">
    <div style="margin-bottom: 4px;">
      <!--<el-button type="primary" size="mini" @click="handleAdd()">新增</el-button>-->
      <!--<el-button type="danger" size="mini" @click="handleDeleteAll()">删除</el-button>-->
    </div>
    <el-table ref="multipleTable" :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column label="客户姓名">
        <template slot-scope="scope">
          {{scope.row.custName}}
        </template>
      </el-table-column>
      <el-table-column label="手机">
        <template slot-scope="scope">
          <span>{{scope.row.mobile}}</span>
        </template>
      </el-table-column>
      <el-table-column label="预约日期">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.appointmentDate, '{y}-{m}-{d}')+' '+scope.row.startTime+'点至'+scope.row.endTime+'点'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="说明">
        <template slot-scope="scope">
          <span>{{scope.row.explanation}}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注">
        <template slot-scope="scope">
          <span>{{scope.row.notes}}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.createTime)}}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="操作">-->
        <!--<template slot-scope="scope">-->
          <!--<el-button-->
            <!--size="mini"-->
            <!--@click="handleEdit(scope.$index, scope.row)">编辑</el-button>-->
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="danger"-->
            <!--@click="handleDelete(scope.$index, scope.row)">删除</el-button>-->
        <!--</template>-->
      <!--</el-table-column>-->
    </el-table>
    <div style="margin-top: 4px;">
      <el-pagination
        background
        layout="total, prev, pager, next"
        :page-size="pageSize"
        :current-page="pageNum"
        :total="pageTotal"
        @current-change="pageChange">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import { appointmentApi } from '@/api/appointment'
  import { parseTime } from '@/utils/index'

  export default {
    data() {
      return {
        pageNum: 1, // 当前页
        pageSize: 20, // 每页数
        pageTotal: 0, // 总页数
        list: null,
        listLoading: true
      }
    },
    filters: {
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        this.listLoading = true
        appointmentApi.getList(this.pageNum, this.pageSize).then(response => {
          console.log(response)
          this.list = response.list
          this.listLoading = false
          this.pageTotal = response.total
          this.pageNum = response.pageNum
        })
      },
      // 时间格式化
      parseTime(time, format) {
        var cformat = format || '{y}-{m}-{d} {h}:{i}:{s}'
        return parseTime(time, cformat)
      },
      pageChange(val) {
        this.pageNum = val
        this.fetchData()
      }
    }
  }
</script>
